home *** CD-ROM | disk | FTP | other *** search
- /*
- sicn ldef.c v1.0
- Copyright 1989 Josh Pritikin
- All rights reserved.
-
- This LDEF may be used freely in any programming project, no string attached.
-
- This LDEF will let you display text as with a normal LDEF except you can
- also attach SICN's to each item. I wrote this to emulate the one in SFDialog.
-
- The data format is as follows:
-
- char index into the SICN resource
- Pstr the item's text
-
- The SICN used is the one that has the same ID as the LDEF. The SICN id
- could be uptained in a more versital way but I didn't want to spend too
- much time on this mini-project.
-
- If you add color capabilities or figure out a better way to specify the
- SICN id, send me a copy of your source.
-
-
- Change History
-
- 12.19.89 Created and tested.
- 12.19.89 v1.0 Release
- 12.19.89 Now the high bit of the sicn index indicates whether to hilite the
- item or not. Set means disabled.
- 12.22.89 If the item is disabled you can't select it anymore. Your appl will
- have to check because the List Mgr thinks the item is selected but
- it wont show on screen.
- 12.19.89 v1.02 Release - (sorry 'bout not making this the first release)
-
- I can be reached at different speed at:
-
- fast-> (every day)
- internet: 6500stom@ucsbuxa.ucsb.edu
- AppleLink: 6500stom%ucsbuxa@hub.ucsb.edu@DASNET#
- CIS: >INTERNET:6500stom%ucsbuxa@hub.ucsb.edu
- slow-> (once a week)
- GEnie: J.Pritikin
- AppleLink: Josh.P
- very slow-> (once a month, if yer lucky)
- CIS: 70771,2131
- */
-
- typedef unsigned char uchar;
-
- /* #define testing */
-
- #ifdef testing
- pascal void ldef128(int message, Boolean select, Rect *bounds, Cell cell,
- int DataOff, int DataLen, ListHandle lhandle)
- #else
- pascal void main(int message, Boolean select, Rect *bounds, Cell cell,
- int DataOff, int DataLen, ListHandle lhandle)
- #endif
- {
- Rect savedOrig;
- GrafPtr aPort, saveport;
- int savedFont, savedSize, savedMode, savedPenVis;
- Style savedFace;
- PenState ps;
-
- if (message == lDrawMsg || message == lHiliteMsg) {
- GetPort(&saveport);
- aPort = (**lhandle).port;
- SetPort(aPort);
-
- savedOrig = aPort->portRect;
- SetOrigin(0,0);
- savedPenVis = aPort->pnVis;
- aPort->pnVis = 0;
- GetPenState(&ps);
-
- savedFont = aPort->txFont;
- savedSize = aPort->txSize;
- savedFace = aPort->txFace;
- savedMode = aPort->txMode;
- TextFont(systemFont);
- TextSize(0);
- TextFace(0);
- TextMode(srcOr);
- }
-
- switch (message) {
- case lInitMsg:
- {
- int id;
- long type;
- Str255 name;
-
- GetResInfo((**lhandle).listDefProc, &id, &type, &name);
- (**lhandle).userHandle = GetResource('SICN', id);
- HPurge((**lhandle).userHandle);
-
- break;
- }
-
- case lDrawMsg:
- {
- Handle sicns;
- uchar index;
- Boolean hilited;
-
- EraseRect(bounds);
- MoveTo(bounds->left + 22, bounds->bottom - 4);
- DrawText(*(**lhandle).cells, DataOff+1, DataLen-1);
-
- index = *(*(Handle)(**lhandle).cells + DataOff);
- if (index >= 0x80) {
- index = index & 0x7f;
- hilited = false;
- } else
- hilited = true;
-
- if (btwn(index, 0, 5)) {
- sicns = (**lhandle).userHandle;
- if (sicns) {
- LoadResource(sicns);
- if (*sicns) {
- BitMap bmap;
- Rect r;
-
- HNoPurge(sicns);
- HLock(sicns);
-
- bmap.baseAddr = *sicns+(index * 32);
- SetRect(&bmap.bounds, 0, 0, 16, 16);
- bmap.rowBytes = 2;
-
- r = bmap.bounds;
- OffsetRect(&r, bounds->left+3, bounds->top);
-
- CopyBits(&bmap, &aPort->portBits, &bmap.bounds, &r, srcOr,
- nil);
-
- HUnlock(sicns);
- HPurge(sicns);
- }
- }
- }
-
- if (!hilited) {
- long gray[2];
-
- PenMode(patBic);
- gray[0] = gray[1] = 0xaa55aa55; /* 50% gray */
- PenPat(gray);
- PaintRect(bounds);
- }
-
- if (!select)
- break;
- }
-
- case lHiliteMsg:
- {
- /* mail me if you figure out how to hilite in color in a BW port
- I suspect you open a new color port, draw and trash it */
-
- if (*(*(Handle)(**lhandle).cells + DataOff) < 0x80)
- InvertRect(bounds);
- break;
- }
-
- case lCloseMsg:
- {
- if ((**lhandle).userHandle)
- ReleaseResource((**lhandle).userHandle);
- break;
- }
- }
-
- if (message == lDrawMsg || message == lHiliteMsg) {
- SetPenState(&ps);
- aPort->pnVis = savedPenVis;
- aPort->portRect = savedOrig;
- TextFont(savedFont);
- TextSize(savedSize);
- TextFace(savedFace);
- TextMode(savedMode);
-
- SetPort(saveport);
- }
- }
-